package cn.javabb.web.controller.pay;

import cn.javabb.core.service.pay.GoodsService;
import cn.javabb.core.base.BaseController;
import cn.javabb.core.entity.pay.GoodsDO;
import cn.javabb.core.plugin.pay.model.PayCallModel;
import cn.javabb.core.service.pay.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author javabb
 * @Date 2019/8/7 0007 下午 1:16
 * @Desc
 */
@Controller
@RequestMapping("/pay")
public class PayController extends BaseController {
    @Autowired
    private GoodsService goodsService;

    @Autowired
    private OrderService orderService;



    @GetMapping("/goods")
    public String toGoodsPage(Model model){
        List<GoodsDO> listGoods = goodsService.list();
        model.addAttribute("listGoods", listGoods);
        return "web/view/pay/goods";
    }
    @GetMapping("/goods/{id}")
    public String toGoodsDetail(@PathVariable Integer id,Model model){
        GoodsDO goods = goodsService.queryById(id);
        model.addAttribute("goods", goods);
        return "web/view/pay/goodsDetail";
    }



    /**
     * 异步通知，收到通知回复success
     * @return
     */
    @PostMapping("/asynCall")
    public String notifyCall(PayCallModel callModel){
        if(null == callModel){
            return "success";
        }
        if(callModel.getStatus() ==1){
            return "success";
        }
        return "success";
    }
    /**
     * 异步通知，收到通知回复success
     * @return
     */
    @PostMapping("/returnCall")
    public String returnCall(PayCallModel callModel){
        if(callModel.getStatus() ==1){
            return "success";
        }
        return "success";
    }


    @GetMapping("/paySuccess")
    public Object paySuccess(String orderId){
        return "web/view/pay/pay-success";
    }




}
